package com.cocostudio.erpapp.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.ImageView;

public class NavigateView extends ImageView {
    private Paint paint;
    private Rect r;
    private int rectWidth;
    private int rectHeight;
    private float zoom = 1;

    public NavigateView(Context context) {
        super(context);
        initPaint();
    }

    public NavigateView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initPaint();
    }

    public NavigateView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initPaint();
    }

    private void initPaint() {
        paint = new Paint();
        paint.setARGB(255, 255, 1, 1);
        paint.setStrokeWidth(2);
        paint.setStyle(Style.STROKE);
        r = new Rect();
    }

    public void moveRectTo(int x, int y) {
        r.offsetTo((int) (x * zoom), (int) (y * zoom));
        invalidate();
    }

    public void setFocusRect(int width, int height) {
        rectWidth = width;
        rectHeight = height;
        r.right = r.left + rectWidth;
        r.bottom = r.top + rectHeight;
        invalidate();
    }

    public void zoom(float v) {
        zoom = v;
        r.right = r.left + (int) (rectWidth * v);
        r.bottom = r.top + (int) (rectHeight * v);
        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawRect(r, paint);
    }
}
